<template>
  <div>
    <h1>组件1的数字是: {{ num }}</h1>
    <Demo></Demo>
    <button @click="addNum(2)">点击+1</button>
    <button @click="reduceNumAsync()">点击-1</button>
  </div>
</template>

<script>
import Demo from './Demo2.vue'
import { mapState, mapMutations, mapActions } from 'vuex'
export default {
  components: {
    Demo
  },
  computed: {
    ...mapState(['num'])
  },
  methods: {
    // addFn() {
    //   this.$store.commit('addNum', 2)
    // },
    // reduceFn() {
    //   this.$store.dispatch('reduceNumAsync')
    // }
    ...mapMutations(['addNum']),
    ...mapActions(['reduceNumAsync'])
  }
}
</script>
